package leetcode.code1260;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<List<Integer>> shiftGrid(int[][] grid, int k) {
		int m = grid.length, n = grid[0].length;
		int[][] ans = new int[m][n];
		// 一列一列做
		for (int j = 0; j < n; j++) {
			int j2 = (j + k) % n;// 最终列
			int imove = (j + k) / n;// 行下移量
			for (int i = 0; i < m; i++) {
				int i2 = (i + imove) % m;// 最终行
				ans[i2][j2] = grid[i][j];
			}
		}
		List<List<Integer>> list = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			List<Integer> row = new ArrayList<>();
			for (int j = 0; j < n; j++) {
				int cur = ans[i][j];
				row.add(cur);
			}
			list.add(row);
		}
		return list;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
